package com.mpp.admin.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mpp.admin.entity.Column;
import com.mpp.admin.entity.Table;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author mapp
 * @des
 * @date 2019/3/13
 */
public interface GeneratorMapper {


    /**
     * 查询表元数据
     * @param page
     * @param dataBaseName
     * @return
     */
    @Select("SELECT\n" +
            "\tTABLE_SCHEMA AS dataBaseName,\n" +
            "\tTABLE_NAME AS tableName,\n" +
            "\t`ENGINE` AS ENGINE,\n" +
            "\tTABLE_COMMENT AS COMMENT,\n" +
            "\tCREATE_TIME AS createTime\n" +
            "FROM\n" +
            "\tinformation_schema. TABLES\n" +
            "WHERE\n" +
            "\ttable_schema  = #{database}")
    List<Table> tableList(IPage page, @Param("database")String dataBaseName);

    /**
     * 列元数据
     * @param dataBaseName
     * @param tableName
     * @return
     */
    @Select("SELECT\n" +
            "\ttable_name AS tableName,\n" +
            "\tCOLUMN_NAME AS columnName,\n" +
            "\tDATA_TYPE AS columnType,\n" +
            "\tCOLUMN_KEY AS columnKey,\n" +
            "\tCOLUMN_COMMENT AS COMMENT\n" +
            "FROM\n" +
            "\tinformation_schema. COLUMNS\n" +
            "WHERE\n" +
            "\tTABLE_SCHEMA = #{database}\n" +
            "AND TABLE_NAME = #{tableName}")
    List<Column> colmunList(@Param("database") String dataBaseName, @Param("tableName") String tableName);
}
